/*
* Copyright (C) 2020 ~ 2024 chaigec All Rights Reserved.
*
* Author:     chaigec <chaigec@163.com>
* Maintainer: chaigec <chaigec@163.com>

 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
*/

#ifndef MK_SIP_UTIL_H
#define MK_SIP_UTIL_H
#include "MkUtil/MkTypes.h"

typedef enum _sip_method
{
    MkSipMethodRegister,
    MkSipMethodInvite,
    MkSipMethodTrying,
    MkSipMethodAck,
    MkSipMethodBye,
    MkSipMethodMessage,
    MkSipMethodInfo,
    MkSipMethodSubscribe,
    MkSipMethodNotify,
    MkSipMethodEnd
}MkSipMethod;

typedef enum _sip_content_type
{
    MkSipContentNone,
    MkSipContentXml,
    MkSipContentSdp,
    MkSipContentRtsp,
    MkSipContentDdcp,
    MkSipContentEnd
}MkSipContentType;

typedef enum _sip_field_type
{
    MkSipFieldVia,
    MkSipFieldTo,
    MkSipFieldFrom,
    MkSipFieldCallId,
    MkSipFieldCseq,
    MkSipFieldProxyAuthorization,
    MkSipFieldProxyAUthenticate,
    MkSipFieldWwwAuthenticate,
    MkSipFieldUserAgent,
    MkSipFieldContentLenght,
    MkSipFieldContact,
    MkSipFieldMaxForwards,
    MkSipFieldExpries,
    MkSipFieldSubject,
    MkSipFieldContentType,
    MkSipFieldRoute,
    MkSipFieldTime
}MkSipFieldType;

typedef enum _sip_request_event
{
    MkSipRequestRegister,
    MkSipRequestMessage,
    MkSipRequestNotify,
    MkSipRequestInvite,
    MkSipRequestInfo,
    MkSipRequestInviteMessage,
    MkSipRequestInviteInfo,
    MkSipRequestSubscribe,
    MkSipRequestSubscribeNotify,
    MkSipRequestBye,
    MkSipRequestAck,
    MkSipRequestEnd
}MkSipRequestEvent;

typedef enum _sip_response_event
{
    MkSipResponseRegister,
    MkSipResponseMessage,
    MkSipResponseInvite,
    MkSipResponseInfo,
    MkSipResponseInviteMessage,
    MkSipResponseInviteInfo,
    MkSipResponseSubscribe,
    MkSipResponseNotify,
    MkSipResponseSubscribeNotify,
    MkSipResponseBye,
    MkSipResponseEnd
}MkSipResponseEvent;

typedef enum _sip_status_code
{
    MkSipStatusTrying = 100,
    MkSipStatusRinging = 180,
    MkSipStatusCallForwarded = 181,
    MkSipStatusQueued = 182,
    MkSipStatusSessionProgress = 183,
    MkSipStatusOK = 200,
    MkSipStatusMultipleChoices = 300,
    MkSipStatusMovedPermanently = 301,
    MkSipStatusMovedTemporarily = 302,
    MkSipStatusUseProxy = 305,
    MkSipStatusAlternativeService = 380,
    MkSipStatusBadRequest = 400,
    MkSipStatusUnauthorized = 401,
    MkSipStatusPaymentRequired = 402,
    MkSipStatusForbidden = 403,
    MkSipStatusNotFound = 404,
    MkSipStatusMethodNotAllowed = 405,
    MkSipStatusNotAcceptable = 406,
    MkSipStatusProxyAuthenticationRequired = 407,
    MkSipStatusRequestTimeout = 408,
    MkSipStatusGone = 410,
    MkSipStatusRequestEntityTooLarge = 413,
    MkSipStatusRequestURITooLong = 414,
    MkSipStatusUnsupportedCodec = 415,
    MkSipStatusUnsupportedURIScheme = 416,
    MkSipStatusBadExtension = 420,
    MkSipStatusExtensionRequired = 421,
    MkSipStatusIntervalTooBrief = 423,
    MkSipStatusTemporarilyUnavailable = 480,
    MkSipStatusCallDoesNotExist = 481,
    MkSipStatusLoopDetected = 482,
    MkSipStatusTooManyHops = 483,
    MkSipStatusAddressIncomplete = 484,
    MkSipStatusAmbiguous = 485,
    MkSipStatusBusyHere = 486,
    MkSipStatusRequestTerminated = 487,
    MkSipStatusNotAcceptableHere = 488,
    MkSipStatusRequestPending = 491,
    MkSipStatusUndecipherable = 493,
    MkSipStatusServerInternalError = 500,
    MkSipStatusNotImplemented = 501,
    MkSipStatusBadGateway = 502,
    MkSipStatusServiceUnavailable = 503,
    MkSipStatusServerTimeOut = 504,
    MkSipStatusVersionNotSupported = 505,
    MkSipStatusMessageTooLarge = 513,
    MkSipStatusBusyEverywhere = 600,
    MkSipStatusDecline = 603,
    MkSipStatusDoesNotExistAnywhere = 604,
    MkSipStatusNotAcceptable606 = 606,
    MkSipStatusEnd = 1000
}MkSipStatus;

class MkApi CMkSipUtil
{
public:
    ~CMkSipUtil();
    static CMkSipUtil& GetInstance() { return m_Instance; }

    void SetMessageContentDebug(BOOL bDebug) { m_bDebugMessageContent = bDebug; }
    Uint32 GetSipMethod(const MkString& strMethod, MkSipMethod& SipCmd) const;
    Uint32 GetSipStringMethod(const MkSipMethod& SipMethod, MkString& StrMethod) const;
    Uint32 GetStatusCodeDesc(const MkSipStatus& Status, MkString& CodeDesc) const;

    const Uint32& GetTransactionCheckSec() const { return m_TransactionCheckSec; }
    const Uint32& GetTransactionTimeOutSec() const { return m_TransactionTimeOutSec; }
    const Uint32& GetTransactionDeleteSec() const { return m_TransactionDeleteSec; }
    const BOOL& DebugMessageContent() const { return m_bDebugMessageContent; }
protected:
private:
    CMkSipUtil();

    static CMkSipUtil m_Instance;

    MkUnorderedMap<MkString, MkSipMethod> m_MapSipMethod;
    MkUnorderedMap<Uint32, MkString> m_MapStatusCodeDesc;

    BOOL    m_bDebugMessageContent;
    Uint32  m_TransactionCheckSec;
    Uint32  m_TransactionTimeOutSec;
    Uint32  m_TransactionDeleteSec;     //delete after this second from transaction complete
};

#endif

